package com.welsy.iter.command
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.welsy.iter.business.*;
	import com.welsy.iter.model.IterModelLocator;
	import com.welsy.util.Comparator;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.controls.Alert;
	import mx.collections.ICollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.utils.ArrayUtil;
	import com.welsy.iter.vo.IterComponentsVO;
	
	/**
	 * @version	$Revision: 1.1 $
	 */
	public class GetItersCommand implements ICommand, Responder
	{
	  	public function GetItersCommand()
		{	 
		}
	
		public function execute( event : CairngormEvent ): void
		{
			var delegate:GetItersDelegate = new GetItersDelegate(this);
			delegate.getIters();
		}
	
		public function onResult( event : * = null ) : void
		{				
			var iters : ICollectionView = ICollectionView( event );
			var model : IterModelLocator = IterModelLocator.getInstance();
			
			/* sort the data
			var sort :Sort = new Sort();
		    sort.fields = [ new SortField( "title", true ) ];
		    courses.sort = sort;
		    courses.refresh();
		    */
	   
	   		if (model.selectedIter == null) {
	   			model.selectedIter = new IterComponentsVO;
	   		}
	   		//model.selectedIter.iter = iters[ 0 ];			
			model.iters = iters;
			trace("GetItersCommand");

			//model.workflowState = IterModelLocator.VIEWING_PRODUCTS_IN_THUMBNAILS;
		}
	
		public function onFault( event : * = null ) : void
		{
			var faultEvent : FaultEvent = FaultEvent( event );
			Alert.show( "Iters could not be retrieved!" );
		}
	}

}